home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume25 / trash / part04 < prev    next >
Encoding:
Text File  |  1992-03-23  |  44.4 KB  |  1,900 lines

  1. Newsgroups: comp.sources.unix
  2. From: bruce@beta.cs.su.oz.au (Bruce Janson)
  3. Subject: v25i158: trash - simulate process execution in MIPS RISC/os 4.52, Part04/08
  4. Sender: unix-sources-moderator@pa.dec.com
  5. Approved: vixie@pa.dec.com
  6.  
  7. Submitted-By: bruce@beta.cs.su.oz.au (Bruce Janson)
  8. Posting-Number: Volume 25, Issue 158
  9. Archive-Name: trash/part04
  10.  
  11. #! /bin/sh
  12. # This is a shell archive.  Remove anything before this line, then unpack
  13. # it by saving it into a file and typing "sh file".  To overwrite existing
  14. # files, type "sh file -c".  You can also feed this as standard input via
  15. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  16. # will see the following message at the end:
  17. #        "End of archive 4 (of 8)."
  18. # Contents:  optab.c process.c
  19. # Wrapped by bruce@basser on Tue Mar  3 23:25:23 1992
  20. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  21. if test -f 'optab.c' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'optab.c'\"
  23. else
  24. echo shar: Extracting \"'optab.c'\" \(16629 characters\)
  25. sed "s/^X//" >'optab.c' <<'END_OF_FILE'
  26. X#include    "diblock.h"
  27. X#include    "instrn.h"
  28. X
  29. Xextern dinstrn    *i_absfmt();
  30. Xextern dinstrn    *i_add();
  31. Xextern dinstrn    *i_addfmt();
  32. Xextern dinstrn    *i_addi();
  33. Xextern dinstrn    *i_addiu();
  34. Xextern dinstrn    *i_addu();
  35. Xextern dinstrn    *i_and();
  36. Xextern dinstrn    *i_andi();
  37. Xextern dinstrn    *i_bc1f();
  38. Xextern dinstrn    *i_bc1t();
  39. Xextern dinstrn    *i_beq();
  40. Xextern dinstrn    *i_bgez();
  41. Xextern dinstrn    *i_bgtz();
  42. Xextern dinstrn    *i_blez();
  43. Xextern dinstrn    *i_bltz();
  44. Xextern dinstrn    *i_bne();
  45. Xextern dinstrn    *i_ceq();
  46. Xextern dinstrn    *i_cfc1();
  47. Xextern dinstrn    *i_cle();
  48. Xextern dinstrn    *i_clt();
  49. Xextern dinstrn    *i_cole();
  50. Xextern dinstrn    *i_colt();
  51. Xextern dinstrn    *i_ctc1();
  52. Xextern dinstrn    *i_cule();
  53. Xextern dinstrn    *i_cult();
  54. Xextern dinstrn    *i_cvtd();
  55. Xextern dinstrn    *i_cvts();
  56. Xextern dinstrn    *i_cvtw();
  57. Xextern dinstrn    *i_div();
  58. Xextern dinstrn    *i_divfmt();
  59. Xextern dinstrn    *i_divu();
  60. Xextern dinstrn    *i_j();
  61. Xextern dinstrn    *i_jal();
  62. Xextern dinstrn    *i_jalr();
  63. Xextern dinstrn    *i_jr();
  64. Xextern dinstrn    *i_lb();
  65. Xextern dinstrn    *i_lbu();
  66. Xextern dinstrn    *i_lh();
  67. Xextern dinstrn    *i_lhu();
  68. Xextern dinstrn    *i_lui();
  69. Xextern dinstrn    *i_lw();
  70. Xextern dinstrn    *i_lwc1();
  71. Xextern dinstrn    *i_lwl();
  72. Xextern dinstrn    *i_lwr();
  73. Xextern dinstrn    *i_mfc1();
  74. Xextern dinstrn    *i_mfhi();
  75. Xextern dinstrn    *i_mflo();
  76. Xextern dinstrn    *i_mtc1();
  77. Xextern dinstrn    *i_mthi();
  78. Xextern dinstrn    *i_mtlo();
  79. Xextern dinstrn    *i_mulfmt();
  80. Xextern dinstrn    *i_mult();
  81. Xextern dinstrn    *i_multu();
  82. Xextern dinstrn    *i_movfmt();
  83. Xextern dinstrn    *i_negfmt();
  84. Xextern dinstrn    *i_nor();
  85. Xextern dinstrn    *i_or();
  86. Xextern dinstrn    *i_ori();
  87. Xextern dinstrn    *i_sb();
  88. Xextern dinstrn    *i_sh();
  89. Xextern dinstrn    *i_sll();
  90. Xextern dinstrn    *i_sllv();
  91. Xextern dinstrn    *i_slt();
  92. Xextern dinstrn    *i_slti();
  93. Xextern dinstrn    *i_sltiu();
  94. Xextern dinstrn    *i_sltu();
  95. Xextern dinstrn    *i_sra();
  96. Xextern dinstrn    *i_srav();
  97. Xextern dinstrn    *i_srl();
  98. Xextern dinstrn    *i_srlv();
  99. Xextern dinstrn    *i_sub();
  100. Xextern dinstrn    *i_subfmt();
  101. Xextern dinstrn    *i_subu();
  102. Xextern dinstrn    *i_sw();
  103. Xextern dinstrn    *i_swc1();
  104. Xextern dinstrn    *i_swl();
  105. Xextern dinstrn    *i_swr();
  106. Xextern dinstrn    *i_syscall();
  107. Xextern dinstrn    *i_undef();
  108. Xextern dinstrn    *i_xor();
  109. Xextern dinstrn    *i_xori();
  110. X
  111. X/*
  112. X * The primary opcode instruction table.
  113. X */
  114. Xinstrn    optab[]    =
  115. X{
  116. X    OP("special",    IF_R,    i_undef,    "????"),
  117. X    OP("bcond",        IF_I,    i_undef,    "????"),
  118. X    OP("j",        IF_J,    i_j,        "a-31"),
  119. X    OP("jal",        IF_J,    i_jal,        "a-32"),
  120. X    OP("beq",        IF_I,    i_beq,        "a-17"),
  121. X    OP("bne",        IF_I,    i_bne,        "a-24"),
  122. X    OP("blez",        IF_I,    i_blez,        "a-21"),
  123. X    OP("bgtz",        IF_I,    i_bgtz,        "a-20"),
  124. X
  125. X    OP("addi",        IF_I,    i_addi,        "a-10"),
  126. X    OP("addiu",        IF_I,    i_addiu,    "a-11"),
  127. X    OP("slti",        IF_I,    i_slti,        "a-65"),
  128. X    OP("sltiu",        IF_I,    i_sltiu,    "a-66"),
  129. X    OP("andi",        IF_I,    i_andi,        "a-14"),
  130. X    OP("ori",        IF_I,    i_ori,        "a-58"),
  131. X    OP("xori",        IF_I,    i_xori,        "a-86"),
  132. X    OP("lui",        IF_I,    i_lui,        "a-39"),
  133. X
  134. X    OP("cop0",        IF_R,    i_undef,    "a-27"),
  135. X    OP("cop1",        IF_U,    i_undef,    "a-27"),
  136. X    OP("cop2",        IF_U,    i_undef,    "a-27"),
  137. X    OP("cop3",        IF_U,    i_undef,    "a-27"),
  138. X    OP("",        IF_U,    i_undef,    "????"),
  139. X    OP("",        IF_U,    i_undef,    "????"),
  140. X    OP("",        IF_U,    i_undef,    "????"),
  141. X    OP("",        IF_U,    i_undef,    "????"),
  142. X
  143. X    OP("",        IF_U,    i_undef,    "????"),
  144. X    OP("",        IF_U,    i_undef,    "????"),
  145. X    OP("",        IF_U,    i_undef,    "????"),
  146. X    OP("",        IF_U,    i_undef,    "????"),
  147. X    OP("",        IF_U,    i_undef,    "????"),
  148. X    OP("",        IF_U,    i_undef,    "????"),
  149. X    OP("",        IF_U,    i_undef,    "????"),
  150. X    OP("",        IF_U,    i_undef,    "????"),
  151. X
  152. X    OP("lb",        IF_I,    i_lb,        "a-35"),
  153. X    OP("lh",        IF_I,    i_lh,        "a-37"),
  154. X    OP("lwl",        IF_I,    i_lwl,        "a-42"),
  155. X    OP("lw",        IF_I,    i_lw,        "a-40"),
  156. X    OP("lbu",        IF_I,    i_lbu,        "a-36"),
  157. X    OP("lhu",        IF_I,    i_lhu,        "a-38"),
  158. X    OP("lwr",        IF_I,    i_lwr,        "a-44"),
  159. X    OP("",        IF_U,    i_undef,    "????"),
  160. X
  161. X    OP("sb",        IF_I,    i_sb,        "a-60"),
  162. X    OP("sh",        IF_I,    i_sh,        "a-61"),
  163. X    OP("swl",        IF_I,    i_swl,        "a-76"),
  164. X    OP("sw",        IF_I,    i_sw,        "a-74"),
  165. X    OP("",        IF_U,    i_undef,    "????"),
  166. X    OP("",        IF_U,    i_undef,    "????"),
  167. X    OP("swr",        IF_I,    i_swr,        "a-78"),
  168. X    OP("",        IF_U,    i_undef,    "????"),
  169. X
  170. X    OP("lwc0",        IF_U,    i_undef,    "a-41"),
  171. X    OP("lwc1",        IF_I,    i_lwc1,        "b-20"),
  172. X    OP("lwc2",        IF_U,    i_undef,    "a-41"),
  173. X    OP("lwc3",        IF_U,    i_undef,    "a-41"),
  174. X    OP("",        IF_U,    i_undef,    "????"),
  175. X    OP("",        IF_U,    i_undef,    "????"),
  176. X    OP("",        IF_U,    i_undef,    "????"),
  177. X    OP("",        IF_U,    i_undef,    "????"),
  178. X
  179. X    OP("swc0",        IF_U,    i_undef,    "a-75"),
  180. X    OP("swc1",        IF_I,    i_swc1,        "b-27"),
  181. X    OP("swc2",        IF_U,    i_undef,    "a-75"),
  182. X    OP("swc3",        IF_U,    i_undef,    "a-75"),
  183. X    OP("",        IF_U,    i_undef,    "????"),
  184. X    OP("",        IF_U,    i_undef,    "????"),
  185. X    OP("",        IF_U,    i_undef,    "????"),
  186. X    OP("",        IF_U,    i_undef,    "????"),
  187. X
  188. X    OP("",        IF_U,    i_undef,    "????"),
  189. X};
  190. X
  191. X/*
  192. X * The special opcode instruction table.
  193. X */
  194. Xinstrn    optab_special[]    =
  195. X{
  196. X    OP("sll",        IF_R,    i_sll,        "a-62"),
  197. X    OP("<special>",    IF_U,    i_undef,    "????"),
  198. X    OP("srl",        IF_R,    i_srl,        "a-70"),
  199. X    OP("sra",        IF_R,    i_sra,        "a-68"),
  200. X    OP("sllv",        IF_R,    i_sllv,        "a-63"),
  201. X    OP("<special>",    IF_U,    i_undef,    "????"),
  202. X    OP("srlv",        IF_R,    i_srlv,        "a-71"),
  203. X    OP("srav",        IF_R,    i_srav,        "a-69"),
  204. X
  205. X    OP("jr",        IF_R,    i_jr,        "a-34"),
  206. X    OP("jalr",        IF_R,    i_jalr,        "a-33"),
  207. X    OP("<special>",    IF_U,    i_undef,    "????"),
  208. X    OP("<special>",    IF_U,    i_undef,    "????"),
  209. X    OP("syscall",    IF_R,    i_syscall,    "a-80"),
  210. X    OP("break",        IF_U,    i_undef,    "a-25"),
  211. X    OP("<special>",    IF_U,    i_undef,    "????"),
  212. X    OP("<special>",    IF_U,    i_undef,    "????"),
  213. X
  214. X    OP("mfhi",        IF_R,    i_mfhi,        "a-48"),
  215. X    OP("mthi",        IF_R,    i_mthi,        "a-52"),
  216. X    OP("mflo",        IF_R,    i_mflo,        "a-49"),
  217. X    OP("mtlo",        IF_R,    i_mtlo,        "a-53"),
  218. X    OP("<special>",    IF_U,    i_undef,    "????"),
  219. X    OP("<special>",    IF_U,    i_undef,    "????"),
  220. X    OP("<special>",    IF_U,    i_undef,    "????"),
  221. X    OP("<special>",    IF_U,    i_undef,    "????"),
  222. X
  223. X    OP("mult",        IF_R,    i_mult,        "a-54"),
  224. X    OP("multu",        IF_R,    i_multu,    "a-55"),
  225. X    OP("div",        IF_R,    i_div,        "a-29"),
  226. X    OP("divu",        IF_R,    i_divu,        "a-30"),
  227. X    OP("<special>",    IF_U,    i_undef,    "????"),
  228. X    OP("<special>",    IF_U,    i_undef,    "????"),
  229. X    OP("<special>",    IF_U,    i_undef,    "????"),
  230. X    OP("<special>",    IF_U,    i_undef,    "????"),
  231. X
  232. X    OP("add",        IF_R,    i_add,        "a-09"),
  233. X    OP("addu",        IF_R,    i_addu,        "a-12"),
  234. X    OP("sub",        IF_R,    i_sub,        "a-72"),
  235. X    OP("subu",        IF_R,    i_subu,        "a-73"),
  236. X    OP("and",        IF_R,    i_and,        "a-13"),
  237. X    OP("or",        IF_R,    i_or,        "a-57"),
  238. X    OP("xor",        IF_R,    i_xor,        "a-85"),
  239. X    OP("nor",        IF_R,    i_nor,        "a-56"),
  240. X
  241. X    OP("<special>",    IF_U,    i_undef,    "????"),
  242. X    OP("<special>",    IF_U,    i_undef,    "????"),
  243. X    OP("slt",        IF_R,    i_slt,        "a-64"),
  244. X    OP("sltu",        IF_R,    i_sltu,        "a-67"),
  245. X    OP("<special>",    IF_U,    i_undef,    "????"),
  246. X    OP("<special>",    IF_U,    i_undef,    "????"),
  247. X    OP("<special>",    IF_U,    i_undef,    "????"),
  248. X    OP("<special>",    IF_U,    i_undef,    "????"),
  249. X
  250. X    OP("<special>",    IF_U,    i_undef,    "????"),
  251. X    OP("<special>",    IF_U,    i_undef,    "????"),
  252. X    OP("<special>",    IF_U,    i_undef,    "????"),
  253. X    OP("<special>",    IF_U,    i_undef,    "????"),
  254. X    OP("<special>",    IF_U,    i_undef,    "????"),
  255. X    OP("<special>",    IF_U,    i_undef,    "????"),
  256. X    OP("<special>",    IF_U,    i_undef,    "????"),
  257. X    OP("<special>",    IF_U,    i_undef,    "????"),
  258. X
  259. X    OP("<special>",    IF_U,    i_undef,    "????"),
  260. X    OP("<special>",    IF_U,    i_undef,    "????"),
  261. X    OP("<special>",    IF_U,    i_undef,    "????"),
  262. X    OP("<special>",    IF_U,    i_undef,    "????"),
  263. X    OP("<special>",    IF_U,    i_undef,    "????"),
  264. X    OP("<special>",    IF_U,    i_undef,    "????"),
  265. X    OP("<special>",    IF_U,    i_undef,    "????"),
  266. X    OP("<special>",    IF_U,    i_undef,    "????"),
  267. X
  268. X    OP("",        IF_U,    i_undef,    "????"),
  269. X};
  270. X
  271. X/*
  272. X * The bcond opcode instruction table.
  273. X */
  274. Xinstrn    optab_bcond[]    =
  275. X{
  276. X    OP("bltz",        IF_I,    i_bltz,        "a-22"),
  277. X    OP("bgez",        IF_I,    i_bgez,        "a-18"),
  278. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  279. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  280. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  281. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  282. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  283. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  284. X
  285. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  286. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  287. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  288. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  289. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  290. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  291. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  292. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  293. X
  294. X    OP("bltzal",    IF_I,    i_undef,    "a-23"),
  295. X    OP("bgezal",    IF_I,    i_undef,    "a-19"),
  296. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  297. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  298. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  299. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  300. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  301. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  302. X
  303. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  304. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  305. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  306. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  307. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  308. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  309. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  310. X    OP("<bcond>",    IF_U,    i_undef,    "????"),
  311. X
  312. X    OP("",        IF_U,    i_undef,    "????"),
  313. X};
  314. X
  315. X/*
  316. X * The cop0 opcode instruction table.
  317. X */
  318. Xinstrn    optab_cop0[]    =
  319. X{
  320. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  321. X    OP("tlbr",        IF_U,    i_undef,    "a-82"),
  322. X    OP("tlbwi",        IF_U,    i_undef,    "a-83"),
  323. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  324. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  325. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  326. X    OP("tlbwr",        IF_U,    i_undef,    "a-84"),
  327. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  328. X
  329. X    OP("tlbp",        IF_U,    i_undef,    "a-81"),
  330. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  331. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  332. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  333. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  334. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  335. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  336. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  337. X
  338. X    OP("rfe",        IF_U,    i_undef,    "a-59"),
  339. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  340. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  341. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  342. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  343. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  344. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  345. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  346. X
  347. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  348. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  349. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  350. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  351. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  352. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  353. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  354. X    OP("<cop0>",    IF_U,    i_undef,    "????"),
  355. X
  356. X    OP("",        IF_U,    i_undef,    "????"),
  357. X};
  358. X
  359. X/*
  360. X * The cop1 group1 opcode instruction table.
  361. X */
  362. Xinstrn    optab_cop1_group1[]    =
  363. X{
  364. X    OP("mfc1",        IF_M1,    i_mfc1,        "b-21"),
  365. X    OP("mfc1",        IF_M1,    i_mfc1,        "b-21"),
  366. X    OP("cfc1",        IF_C1,    i_cfc1,        "b-14"),
  367. X    OP("cfc1",        IF_C1,    i_cfc1,        "b-14"),
  368. X    OP("mtc1",        IF_M1,    i_mtc1,        "b-23"),
  369. X    OP("mtc1",        IF_M1,    i_mtc1,        "b-23"),
  370. X    OP("ctc1",        IF_C1,    i_ctc1,        "b-15"),
  371. X    OP("ctc1",        IF_C1,    i_ctc1,        "b-15"),
  372. X
  373. X    OP("bc1f",        IF_I1,    i_bc1f,        "b-10"),
  374. X    OP("bc1t",        IF_I1,    i_bc1t,        "b-11"),
  375. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  376. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  377. X    OP("bc1f",        IF_I1,    i_bc1f,        "b-10"),
  378. X    OP("bc1t",        IF_I1,    i_bc1t,        "b-11"),
  379. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  380. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  381. X
  382. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  383. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  384. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  385. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  386. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  387. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  388. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  389. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  390. X
  391. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  392. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  393. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  394. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  395. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  396. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  397. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  398. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  399. X
  400. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  401. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  402. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  403. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  404. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  405. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  406. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  407. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  408. X
  409. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  410. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  411. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  412. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  413. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  414. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  415. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  416. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  417. X
  418. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  419. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  420. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  421. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  422. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  423. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  424. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  425. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  426. X
  427. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  428. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  429. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  430. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  431. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  432. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  433. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  434. X    OP("<cop1.1>",    IF_U,    i_undef,    "????"),
  435. X
  436. X    OP("",        IF_U,    i_undef,    "????"),
  437. X};
  438. X
  439. X/*
  440. X * The cop1 group2 opcode instruction table.
  441. X */
  442. Xinstrn    optab_cop1_group2[]    =
  443. X{
  444. X    OP("add.fmt",    IF_R1,    i_addfmt,    "b-09"),
  445. X    OP("sub.fmt",    IF_R1,    i_subfmt,    "b-26"),
  446. X    OP("mul.fmt",    IF_R1,    i_mulfmt,    "b-24"),
  447. X    OP("div.fmt",    IF_R1,    i_divfmt,    "b-19"),
  448. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  449. X    OP("abs.fmt",    IF_R1,    i_absfmt,    "b-08"),
  450. X    OP("mov.fmt",    IF_R1,    i_movfmt,    "b-22"),
  451. X    OP("neg.fmt",    IF_R1,    i_negfmt,    "b-25"),
  452. X
  453. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  454. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  455. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  456. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  457. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  458. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  459. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  460. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  461. X
  462. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  463. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  464. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  465. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  466. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  467. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  468. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  469. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  470. X
  471. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  472. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  473. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  474. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  475. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  476. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  477. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  478. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  479. X
  480. X    OP("cvt.s",        IF_R1,    i_cvts,        "b-17"),
  481. X    OP("cvt.d",        IF_R1,    i_cvtd,        "b-16"),
  482. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  483. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  484. X    OP("cvt.w",        IF_R1,    i_cvtw,        "b-18"),
  485. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  486. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  487. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  488. X
  489. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  490. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  491. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  492. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  493. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  494. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  495. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  496. X    OP("<cop1.2>",    IF_U,    i_undef,    "????"),
  497. X
  498. X    OP("c.f",        IF_R1,    i_undef,    "b-12"),
  499. X    OP("c.un",        IF_R1,    i_undef,    "b-12"),
  500. X    OP("c.eq",        IF_R1,    i_ceq,        "b-12"),
  501. X    OP("c.ueq",        IF_R1,    i_undef,    "b-12"),
  502. X    OP("c.olt",        IF_R1,    i_colt,        "b-12"),
  503. X    OP("c.ult",        IF_R1,    i_cult,        "b-12"),
  504. X    OP("c.ole",        IF_R1,    i_cole,        "b-12"),
  505. X    OP("c.ule",        IF_R1,    i_cule,        "b-12"),
  506. X
  507. X    OP("c.sf",        IF_R1,    i_undef,    "b-12"),
  508. X    OP("c.ngle",    IF_R1,    i_undef,    "b-12"),
  509. X    OP("c.seq",        IF_R1,    i_undef,    "b-12"),
  510. X    OP("c.ngl",        IF_R1,    i_undef,    "b-12"),
  511. X    OP("c.lt",        IF_R1,    i_clt,        "b-12"),
  512. X    OP("c.nge",        IF_R1,    i_undef,    "b-12"),
  513. X    OP("c.le",        IF_R1,    i_cle,        "b-12"),
  514. X    OP("c.ngt",        IF_R1,    i_undef,    "b-12"),
  515. X
  516. X    OP("",        IF_U,    i_undef,    "????"),
  517. X};
  518. X
  519. Xinstrn    *
  520. Xgetip(i)
  521. Xunsigned long    i;
  522. X{
  523. X    unsigned long    opindex;
  524. X    instrn        *ip;
  525. X
  526. X    opindex = i_to_op(i);
  527. X
  528. X    switch (opindex)
  529. X    {
  530. X    case 0:        /* special */
  531. X        ip = &optab_special[i_to_funct(i)];
  532. X        break;
  533. X
  534. X    case 1:        /* bcond */
  535. X        ip = &optab_bcond[i_to_rt(i)];
  536. X        break;
  537. X
  538. X    case 16:    /* coprocessor 0 */
  539. X        ip = &optab_cop0[i_to_funct(i) & 0x1F];
  540. X        break;
  541. X
  542. X    case 17:    /* coprocessor 1 */
  543. X        if (is_cop1_group1(i))
  544. X            ip = &optab_cop1_group1[i_to_cop1_group1(i)];
  545. X        else
  546. X            ip = &optab_cop1_group2[i_to_cop1_group2(i)];
  547. X        break;
  548. X
  549. X    default:
  550. X        ip = &optab[opindex];
  551. X        break;
  552. X    }
  553. X
  554. X    return ip;
  555. X}
  556. END_OF_FILE
  557. if test 16629 -ne `wc -c <'optab.c'`; then
  558.     echo shar: \"'optab.c'\" unpacked with wrong size!
  559. fi
  560. # end of 'optab.c'
  561. fi
  562. if test -f 'process.c' -a "${1}" != "-c" ; then 
  563.   echo shar: Will not clobber existing file \"'process.c'\"
  564. else
  565. echo shar: Extracting \"'process.c'\" \(25029 characters\)
  566. sed "s/^X//" >'process.c' <<'END_OF_FILE'
  567. X#include    <fcntl.h>
  568. X#include    <stdio.h>
  569. X#include    <unistd.h>
  570. X#include    <filehdr.h>
  571. X#include    <scnhdr.h>
  572. X#include    <syms.h>
  573. X#include    <ldfcn.h>
  574. X#include    <aouthdr.h>
  575. X#include    <errno.h>
  576. X#include    "register.h"
  577. X#include    "symtab.h"
  578. X#include    "diblock.h"
  579. X#include    "instrn.h"
  580. X#include    "process.h"
  581. X#include    "wcache.h"
  582. X#include    "nels.h"
  583. X
  584. X#if    0
  585. X#endif    /* 0 */
  586. X#define    SPECIAL_MEMCPY
  587. X
  588. X#if    defined(SPECIAL_MEMCPY)
  589. X#define    Wmemcpy(to,from,n) \
  590. X{ \
  591. X    if \
  592. X    ( \
  593. X        (n) == sizeof(unsigned long) \
  594. X        && \
  595. X        (((unsigned long)(from)) & 0x3) == 0x0 \
  596. X        && \
  597. X        (((unsigned long)(to)) & 0x3) == 0x0 \
  598. X    ) \
  599. X        *(unsigned long *)(to) = *(unsigned long *)(from); \
  600. X    else \
  601. X        (void)memcpy((to), (from), (n)); \
  602. X}
  603. X#else    /* defined(SPECIAL_MEMCPY) */
  604. X#define    Wmemcpy(to,from,n)    (void)memcpy((to), (from), (n))
  605. X#endif    /* defined(SPECIAL_MEMCPY) */
  606. X
  607. Xextern void            couldnot();
  608. Xextern void            warning();
  609. Xextern char            *strdup();
  610. Xextern char            *say_register();
  611. Xextern int            symtab_open();
  612. Xextern int            symtab_close();
  613. Xextern char            *symtab_text_address();
  614. Xextern LDFILE            *my_ldopen();
  615. Xextern int            histo_init();
  616. Xextern char            *proc_text_address();
  617. Xextern int            clear_decoded_page();
  618. X
  619. Xextern int            errno;
  620. X
  621. Xextern FILE            *outfp;
  622. X
  623. Xextern int            Cflag;
  624. Xextern int            Hflag;
  625. Xextern int            Vflag;
  626. X
  627. Xprocess                P;
  628. Xint                give_warnings        = 1;
  629. X
  630. Xstatic int            ld_section_read();
  631. Xstatic int            procimput();
  632. X
  633. Xint
  634. Xprocopen(adotout)
  635. Xchar    *adotout;
  636. X{
  637. X    FILE        *fp;
  638. X    LDFILE        *ldptr;
  639. X    struct filehdr    *fhp;
  640. X    unsigned short    sectindx;
  641. X    SCNHDR        secthead;
  642. X    AOUTHDR        adotout_header;
  643. X    int        i;
  644. X    int        length;
  645. X
  646. X    if ((P.p_adotout = strdup(adotout)) == (char *)0)
  647. X        return -1;
  648. X
  649. X    P.p_pid = getpid();
  650. X
  651. X    /*
  652. X     * Read the executable and initialise
  653. X     * our memory image of it.
  654. X     */
  655. X
  656. X    if ((ldptr = my_ldopen(adotout, (LDFILE *)0)) == (LDFILE *)0)
  657. X        return -1;
  658. X
  659. X    if (ISARCHIVE(TYPE(ldptr)))
  660. X    {
  661. X        vcouldnot("interpret contents of archive \"%s\"", adotout);
  662. X        (void)ldclose(ldptr);
  663. X        return -1;
  664. X    }
  665. X
  666. X    fhp = &HEADER(ldptr);
  667. X
  668. X    if (!ISCOFF(fhp->f_magic))
  669. X    {
  670. X        vcouldnot("interpret contents of non-COFF executable \"%s\"", adotout);
  671. X        (void)ldclose(ldptr);
  672. X        return -1;
  673. X    }
  674. X
  675. X    /*
  676. X     * Determine the entry point of the process.
  677. X     */
  678. X    if (ldohseek(ldptr) != SUCCESS)
  679. X    {
  680. X        vcouldnot("seek to start of optional header structure in executable \"%s\"", adotout);
  681. X        (void)ldclose(ldptr);
  682. X        return -1;
  683. X    }
  684. X
  685. X    if (FREAD(&adotout_header, sizeof(adotout_header), 1, ldptr) != 1)
  686. X    {
  687. X        vcouldnot("read optional header structure from executable \"%s\"", adotout);
  688. X        (void)ldclose(ldptr);
  689. X        return -1;
  690. X    }
  691. X
  692. X    if (Vflag)
  693. X    {
  694. X        fprintf(outfp, "magic == 0%o\n", adotout_header.magic);
  695. X        fprintf(outfp, "vstamp == 0x%x(%d)\n", adotout_header.vstamp, adotout_header.vstamp);
  696. X        fprintf(outfp, "tsize == 0x%x(%d)\n", adotout_header.tsize, adotout_header.tsize);
  697. X        fprintf(outfp, "dsize == 0x%x(%d)\n", adotout_header.dsize, adotout_header.dsize);
  698. X        fprintf(outfp, "bsize == 0x%x(%d)\n", adotout_header.bsize, adotout_header.bsize);
  699. X        fprintf(outfp, "entry == 0x%x(%d)\n", adotout_header.entry, adotout_header.entry);
  700. X        fprintf(outfp, "text_start == 0x%x(%d)\n", adotout_header.text_start, adotout_header.text_start);
  701. X        fprintf(outfp, "data_start == 0x%x(%d)\n", adotout_header.data_start, adotout_header.data_start);
  702. X        fprintf(outfp, "bss_start == 0x%x(%d)\n", adotout_header.bss_start, adotout_header.bss_start);
  703. X        fprintf(outfp, "gprmask == 0x%x(%d)\n", adotout_header.gprmask, adotout_header.gprmask);
  704. X        fprintf(outfp, "gp_value == 0x%x(%d)\n", adotout_header.gp_value, adotout_header.gp_value);
  705. X    }
  706. X
  707. X    if (adotout_header.magic == OMAGIC)
  708. X        P.p_text_region_is_readonly = 0;
  709. X    else
  710. X        P.p_text_region_is_readonly = 1;
  711. X
  712. X    /*
  713. X     * Initialise the PC as the process's entry point.
  714. X     */
  715. X    P.p_entry_point = adotout_header.entry;
  716. X
  717. X    P.p_text_region_min = adotout_header.text_start;
  718. X    P.p_text_region_limit = P.p_text_region_min + adotout_header.tsize - 1;
  719. X    P.p_text_region_wlimit = P.p_text_region_limit + 1 - sizeof(unsigned long);
  720. X    P.p_text_region = calloc(adotout_header.tsize / sizeof(unsigned long), sizeof(unsigned long));
  721. X    if (P.p_text_region == (unsigned char *)0)
  722. X    {
  723. X        vcouldnot("grow text space to size %d bytes", adotout_header.tsize);
  724. X        (void)ldclose(ldptr);
  725. X        return -1;
  726. X    }
  727. X
  728. X    P.p_data_region_min = adotout_header.data_start;
  729. X
  730. X    /*
  731. X     * Initialise GP to the process's gp value.
  732. X     */
  733. X    if (quiet_procsput(R_GP, adotout_header.gp_value) == -1)
  734. X    {
  735. X        (void)ldclose(ldptr);
  736. X        return -1;
  737. X    }
  738. X
  739. X    /*
  740. X     * Read each COFF section in turn, copying the data of those
  741. X     * that are required to memory.
  742. X     */
  743. X    sectindx = 1;
  744. X    while (ldshread(ldptr, sectindx, §head) == SUCCESS)
  745. X    {
  746. X        if (Vflag)
  747. X        {
  748. X            fprintf
  749. X            (
  750. X                outfp,
  751. X                "read section %d: name=\"%s\",paddr=0x%x,vaddr=0x%x,size=%d,scnptr=%d,relptr=%d,lnnoptr=%d,nreloc=%d,nlnno=%d,flags=0x%x\n",
  752. X                sectindx,
  753. X                §head.s_name[0],
  754. X                secthead.s_paddr,
  755. X                secthead.s_vaddr,
  756. X                secthead.s_size,
  757. X                secthead.s_scnptr,
  758. X                secthead.s_relptr,
  759. X                secthead.s_lnnoptr,
  760. X                secthead.s_nreloc,
  761. X                secthead.s_nlnno,
  762. X                secthead.s_flags
  763. X            );
  764. X        }
  765. X
  766. X        switch (secthead.s_flags & 0xF)
  767. X        {
  768. X        case STYP_REG:
  769. X            if (Vflag)
  770. X                fprintf(outfp, "STYP_REG: allocated, relocated, loaded\n");
  771. X            break;
  772. X
  773. X        case STYP_DSECT:
  774. X            if (Vflag)
  775. X                fprintf(outfp, "STYP_DSECT: not allocated, relocated, not loaded\n");
  776. X            break;
  777. X
  778. X        case STYP_NOLOAD:
  779. X            if (Vflag)
  780. X                fprintf(outfp, "STYP_NOLOAD: allocated, relocated, not loaded\n");
  781. X            break;
  782. X
  783. X        case STYP_GROUP:
  784. X            if (Vflag)
  785. X                fprintf(outfp, "STYP_GROUP: grouped\n");
  786. X            break;
  787. X
  788. X        case STYP_PAD:
  789. X            if (Vflag)
  790. X                fprintf(outfp, "STYP_PAD: not allocated, not relocated, loaded\n");
  791. X            break;
  792. X
  793. X        default:
  794. X            vcouldnot("recognise section type 0x%x", secthead.s_flags & 0xF);
  795. X            (void)ldclose(ldptr);
  796. X            return -1;
  797. X        }
  798. X
  799. X        switch (secthead.s_flags & ~0xF)
  800. X        {
  801. X        case STYP_COPY:
  802. X            if (Vflag)
  803. X                fprintf(outfp, "STYP_COPY: not allocated, not relocated, loaded\n");
  804. X            break;
  805. X
  806. X        case STYP_TEXT:
  807. X            if (Vflag)
  808. X                fprintf(outfp, "STYP_TEXT: text only\n");
  809. X            break;
  810. X
  811. X        case STYP_DATA:
  812. X            if (Vflag)
  813. X                fprintf(outfp, "STYP_DATA: data only\n");
  814. X            break;
  815. X
  816. X        case STYP_BSS:
  817. X            if (Vflag)
  818. X                fprintf(outfp, "STYP_BSS: bss only\n");
  819. X            break;
  820. X
  821. X        case STYP_RDATA:
  822. X            if (Vflag)
  823. X                fprintf(outfp, "STYP_RDATA: read only data only\n");
  824. X            break;
  825. X
  826. X        case STYP_SDATA:
  827. X            if (Vflag)
  828. X                fprintf(outfp, "STYP_SDATA: small data only\n");
  829. X            break;
  830. X
  831. X        case STYP_SBSS:
  832. X            if (Vflag)
  833. X                fprintf(outfp, "STYP_SBSS: small bss only\n");
  834. X            break;
  835. X
  836. X        case STYP_UCODE:
  837. X            if (Vflag)
  838. X                fprintf(outfp, "STYP_UCODE: ucode only\n");
  839. X            break;
  840. X
  841. X        case STYP_LIT8:
  842. X            if (Vflag)
  843. X                fprintf(outfp, "STYP_LIT8: literal pool for 8-byte literals\n");
  844. X            break;
  845. X
  846. X        case STYP_LIT4:
  847. X            if (Vflag)
  848. X                fprintf(outfp, "STYP_LIT4: literal pool for 4-byte literals\n");
  849. X            break;
  850. X
  851. X        case S_NRELOC_OVFL:
  852. X            if (Vflag)
  853. X                fprintf(outfp, "S_NRELOC_OVFL: s_nreloc overflowed, the value is in v_addr of the first entry\n");
  854. X            break;
  855. X
  856. X        case STYP_LIB:
  857. X            if (Vflag)
  858. X                fprintf(outfp, "STYP_LIB: section is a .lib section\n");
  859. X            break;
  860. X
  861. X        case STYP_INIT:
  862. X            if (Vflag)
  863. X                fprintf(outfp, "STYP_INIT: section only contains the text instructions for the .init sec.\n");
  864. X            break;
  865. X
  866. X        default:
  867. X            vcouldnot("recognise section type 0x%x", secthead.s_flags & ~0xF);
  868. X            (void)ldclose(ldptr);
  869. X            return -1;
  870. X        }
  871. X
  872. X        if (strcmp(§head.s_name[0], ".lib") == 0)
  873. X        {
  874. X            vcouldnot("handle executable containing a .lib (call to shared library) section");
  875. X            return -1;
  876. X        }
  877. X        else if (strcmp(§head.s_name[0], ".data") == 0)
  878. X        {
  879. X            /*
  880. X             * Initialise the start of the writable data.
  881. X             */
  882. X            if (quiet_procwrdataput(secthead.s_vaddr) == -1)
  883. X            {
  884. X                (void)ldclose(ldptr);
  885. X                return -1;
  886. X            }
  887. X        }
  888. X        else if (strcmp(§head.s_name[0], ".bss") == 0)
  889. X        {
  890. X            /*
  891. X             * Initialise The Break.
  892. X             */
  893. X            if (procbreakput(secthead.s_vaddr + secthead.s_size) == -1)
  894. X            {
  895. X                vcouldnot("set break to 0x%x", secthead.s_vaddr + secthead.s_size);
  896. X                (void)ldclose(ldptr);
  897. X                return -1;
  898. X            }
  899. X        }
  900. X
  901. X        if (ld_section_read(ldptr, secthead.s_scnptr, secthead.s_vaddr, secthead.s_size) == -1)
  902. X        {
  903. X            (void)ldclose(ldptr);
  904. X            return -1;
  905. X        }
  906. X
  907. X        sectindx++;
  908. X    }
  909. X
  910. X    if (symtab_open(ldptr, adotout, &P.p_symtab) == -1)
  911. X    {
  912. X        (void)ldclose(ldptr);
  913. X        return -1;
  914. X    }
  915. X
  916. X    /*
  917. X     * Close the executable file.
  918. X     */
  919. X    if (ldclose(ldptr) != SUCCESS)
  920. X    {
  921. X        vcouldnot("close executable \"%s\"", adotout);
  922. X        return -1;
  923. X    }
  924. X
  925. X    if (Hflag)
  926. X    {
  927. X        if (histo_init(P.p_text_region_min, P.p_text_region_limit + 1 - P.p_text_region_min) == -1)
  928. X            return -1;
  929. X    }
  930. X
  931. X    P.p_stack_region_min = STACK_MAX + 1;
  932. X
  933. X    return 0;
  934. X}
  935. X
  936. Xstatic
  937. Xint
  938. Xld_section_read(srce_ldptr, srce_offset, dest_offset, count)
  939. XLDFILE    *srce_ldptr;
  940. Xlong    srce_offset;
  941. Xlong    dest_offset;
  942. Xlong    count;
  943. X{
  944. X    unsigned char    buf[64 * 1024];
  945. X
  946. X    if (srce_offset == (long)0)
  947. X        (void)memset(&buf[0], 0x00, sizeof(buf));
  948. X    else
  949. X    {
  950. X        if (FSEEK(srce_ldptr, srce_offset, SEEK_SET) != 0)
  951. X        {
  952. X            vcouldnot("FSEEK to offset %d in source file in ld_section_read()", srce_offset);
  953. X            return -1;
  954. X        }
  955. X    }
  956. X
  957. X    while (count > 0)
  958. X    {
  959. X        int    chunk;
  960. X
  961. X        chunk = (count >= sizeof(buf)) ? sizeof(buf) : count;
  962. X
  963. X        if (srce_offset != (long)0)
  964. X        {
  965. X            if (FREAD(&buf[0], chunk, 1, srce_ldptr) != 1)
  966. X            {
  967. X                vcouldnot("FREAD from source file in ld_section_read()");
  968. X                return -1;
  969. X            }
  970. X        }
  971. X
  972. X        if (procimput(dest_offset, &buf[0], chunk) == -1)
  973. X            return -1;
  974. X
  975. X        count -= chunk;
  976. X        dest_offset += chunk;
  977. X    }
  978. X
  979. X    return 0;
  980. X}
  981. X
  982. Xint
  983. Xprocclose()
  984. X{
  985. X    FILE    *fp;
  986. X    int    mi;
  987. X    int    i;
  988. X
  989. X    if (P.p_stack_region != (unsigned char *)0)
  990. X        (void)free(P.p_stack_region);
  991. X
  992. X    if (P.p_data_region != (unsigned char *)0)
  993. X        (void)free(P.p_data_region);
  994. X
  995. X    if (P.p_text_region != (unsigned char *)0)
  996. X        (void)free(P.p_text_region);
  997. X
  998. X    if (symtab_close(&P.p_symtab) == -1)
  999. X        return -1;
  1000. X
  1001. X    if (P.p_adotout != (char *)0)
  1002. X    {
  1003. X        (void)free(P.p_adotout);
  1004. X        P.p_adotout = (char *)0;
  1005. X    }
  1006. X
  1007. X    (void)fflush(outfp);
  1008. X
  1009. X    return 0;
  1010. X}
  1011. X
  1012. Xvoid
  1013. Xprocsput_trace(regi, v)
  1014. Xint        regi;
  1015. Xunsigned long    v;
  1016. X{
  1017. X    if (Cflag)
  1018. X    {
  1019. X        switch (regi)
  1020. X        {
  1021. X        case R_0:
  1022. X            break;
  1023. X
  1024. X        case R_GP:
  1025. X        case R_RA:
  1026. X        case R_SP:
  1027. X            fprintf(outfp, "%6d:\t%s = %s;\n", P.p_pid, say_register(regi), proc_text_address(v));
  1028. X            break;
  1029. X
  1030. X        default:
  1031. X            fprintf(outfp, "%6d:\t%s = 0x%08x;\n", P.p_pid, say_register(regi), v);
  1032. X            break;
  1033. X        }
  1034. X    }
  1035. X    else
  1036. X        fprintf(outfp, "\t\tprocsput(%d, %s, %d)\n", P.p_pid, say_register(regi), v);
  1037. X}
  1038. X
  1039. Xvoid
  1040. Xprocsget_trace(regi, r)
  1041. Xint        regi;
  1042. Xunsigned long    r;
  1043. X{
  1044. X    if (Cflag)
  1045. X    {
  1046. X#if    0
  1047. X        switch (regi)
  1048. X        {
  1049. X        case R_RA:
  1050. X            fprintf(outfp, "%6d:\t? = %s /* %s */;\n", P.p_pid, say_register(regi), proc_text_address(r));
  1051. X            break;
  1052. X
  1053. X        default:
  1054. X            fprintf(outfp, "%6d:\t? = %s /* 0x%08x */;\n", P.p_pid, say_register(regi), r);
  1055. X            break;
  1056. X        }
  1057. X#endif    /* 0 */
  1058. X    }
  1059. X    else
  1060. X        fprintf(outfp, "\t\tprocsget(%d, %s, %d)\n", P.p_pid, say_register(regi), r);
  1061. X}
  1062. X
  1063. Xvoid
  1064. Xprocmput_trace(offset, cp, length)
  1065. Xunsigned long    offset;
  1066. Xchar        *cp;
  1067. Xint        length;
  1068. X{
  1069. X    if (Cflag)
  1070. X    {
  1071. X        while (length >= sizeof(int))
  1072. X        {
  1073. X            fprintf(outfp, "%6d:\t*(int *)%s = 0x%08x;\n", P.p_pid, proc_text_address(offset), *(int *)cp);
  1074. X            length -= sizeof(int);
  1075. X            cp += sizeof(int);
  1076. X            offset += sizeof(int);
  1077. X        }
  1078. X
  1079. X        while (length >= sizeof(short))
  1080. X        {
  1081. X            fprintf(outfp, "%6d:\t*(short *)%s = 0x%04x;\n", P.p_pid, proc_text_address(offset), *(short *)cp);
  1082. X            length -= sizeof(short);
  1083. X            cp += sizeof(short);
  1084. X            offset += sizeof(short);
  1085. X        }
  1086. X
  1087. X        while (length >= sizeof(char))
  1088. X        {
  1089. X            fprintf(outfp, "%6d:\t*(char *)%s = 0x%02x;\n", P.p_pid, proc_text_address(offset), *(unsigned char *)cp);
  1090. X            length -= sizeof(char);
  1091. X            cp += sizeof(char);
  1092. X            offset += sizeof(char);
  1093. X        }
  1094. X    }
  1095. X    else
  1096. X        fprintf(outfp, "\t\t\tprocmput(pid=%d,offset=%d,length=%d)\n", P.p_pid, offset, length);
  1097. X}
  1098. X
  1099. Xvoid
  1100. Xprocmget_trace(offset, cp, length)
  1101. Xunsigned long    offset;
  1102. Xchar        *cp;
  1103. Xint        length;
  1104. X{
  1105. X    if (Cflag)
  1106. X    {
  1107. X#if    0
  1108. X        while (length >= sizeof(int))
  1109. X        {
  1110. X            fprintf(outfp, "%6d:\t? = *(int *)%s /* 0x%08x */;\n", P.p_pid, proc_text_address(offset), *(int *)cp);
  1111. X            length -= sizeof(int);
  1112. X            cp += sizeof(int);
  1113. X            offset += sizeof(int);
  1114. X        }
  1115. X
  1116. X        while (length >= sizeof(short))
  1117. X        {
  1118. X            fprintf(outfp, "%6d:\t? = *(short *)%s /* 0x%04x */;\n", P.p_pid, proc_text_address(offset), *(short *)cp);
  1119. X            length -= sizeof(short);
  1120. X            cp += sizeof(short);
  1121. X            offset += sizeof(short);
  1122. X        }
  1123. X
  1124. X        while (length >= sizeof(char))
  1125. X        {
  1126. X            fprintf(outfp, "%6d:\t? = *(char *)%s /* 0x%02x */;\n", P.p_pid, proc_text_address(offset), *(unsigned char *)cp);
  1127. X            length -= sizeof(char);
  1128. X            cp += sizeof(char);
  1129. X            offset += sizeof(char);
  1130. X        }
  1131. X#endif    /* 0 */
  1132. X    }
  1133. X    else
  1134. X        fprintf(outfp, "\t\t\tprocmget(pid=%d,offset=%d,length=%d)\n", P.p_pid, offset, length);
  1135. X}
  1136. X
  1137. Xvoid
  1138. Xprocsget_warning(regi)
  1139. Xint    regi;
  1140. X{
  1141. X    warning("read from kernel-reserved register %s", say_register(regi));
  1142. X}
  1143. X
  1144. Xint
  1145. Xprocbreakput(newbrk)
  1146. Xunsigned long    newbrk;
  1147. X{
  1148. X    unsigned long    new_region_size;
  1149. X    unsigned char    *new_region;
  1150. X
  1151. X    wcache_clear();
  1152. X
  1153. X    new_region_size = newbrk - P.p_data_region_min;
  1154. X
  1155. X    if ((new_region = calloc(new_region_size, 1)) == (unsigned char *)0)
  1156. X        return -1;
  1157. X
  1158. X    if (P.p_data_region != (unsigned char *)0)
  1159. X    {
  1160. X        unsigned long    p_data_region_size;
  1161. X
  1162. X        p_data_region_size = P.p_data_region_limit + 1 - P.p_data_region_min;
  1163. X
  1164. X        (void)memcpy(new_region, P.p_data_region, (new_region_size < p_data_region_size) ? new_region_size : p_data_region_size);
  1165. X        (void)free(P.p_data_region);
  1166. X    }
  1167. X
  1168. X    P.p_data_region = new_region;
  1169. X    P.p_data_region_limit = newbrk - 1;
  1170. X    P.p_data_region_wlimit = P.p_data_region_limit + 1 - sizeof(unsigned long);
  1171. X
  1172. X    return 0;
  1173. X}
  1174. X
  1175. Xint
  1176. Xprocbreakget(oldbrkp)
  1177. Xunsigned long    *oldbrkp;
  1178. X{
  1179. X    *oldbrkp = P.p_data_region_limit + 1;
  1180. X
  1181. X    return 0;
  1182. X}
  1183. X
  1184. Xint
  1185. Xprocwrdataput(newwrdata)
  1186. Xunsigned long    newwrdata;
  1187. X{
  1188. X    P.p_writable_data = newwrdata;
  1189. X
  1190. X    return 0;
  1191. X}
  1192. X
  1193. Xint
  1194. Xprocwrdataget(oldwrdatap)
  1195. Xunsigned long    *oldwrdatap;
  1196. X{
  1197. X    *oldwrdatap = P.p_writable_data;
  1198. X
  1199. X    return 0;
  1200. X}
  1201. X
  1202. Xstatic
  1203. Xint
  1204. Xprocimput(offset, cp, length)
  1205. Xunsigned long    offset;
  1206. Xunsigned char    *cp;
  1207. Xint        length;
  1208. X{
  1209. X    unsigned long    limit;
  1210. X    int        i;
  1211. X
  1212. X    limit = offset + length - 1;
  1213. X
  1214. X    if (limit <= P.p_text_region_limit)
  1215. X    {
  1216. X        if ((i = offset - P.p_text_region_min) < 0)
  1217. X        {
  1218. X            vcouldnot("write %d byte%s at text address 0x%x: illegal (too small) address", length, (length == 1) ? "" : "s", offset);
  1219. X            return -1;
  1220. X        }
  1221. X
  1222. X        Wmemcpy(&P.p_text_region[i], cp, length);
  1223. X    }
  1224. X    else if (limit <= DATA_MAX)
  1225. X    {
  1226. X        if ((i = offset - P.p_data_region_min) < 0)
  1227. X        {
  1228. X            vcouldnot("write %d byte%s at data address 0x%x: illegal (too small) address", length, (length == 1) ? "" : "s", offset);
  1229. X            return -1;
  1230. X        }
  1231. X
  1232. X        if (limit > P.p_data_region_limit)
  1233. X        {
  1234. X            if (procbreakput(limit + 1) == -1)
  1235. X            {
  1236. X                vcouldnot("set break to 0x%x", limit + 1);
  1237. X                return -1;
  1238. X            }
  1239. X        }
  1240. X
  1241. X        Wmemcpy(&P.p_data_region[i], cp, length);
  1242. X    }
  1243. X    else
  1244. X    {
  1245. X        /*
  1246. X         * Stack space or above.
  1247. X         */
  1248. X        vcouldnot("write %d byte%s at non-text, non-data address 0x%x: illegal (too big) address", length, (length == 1) ? "" : "s", offset);
  1249. X        return -1;
  1250. X    }
  1251. X
  1252. X    return 0;
  1253. X}
  1254. X
  1255. X/*
  1256. X * Grow the stack down to include 'offset'.
  1257. X */
  1258. Xint
  1259. Xproc_grow_stack(dipc, offset)
  1260. Xdinstrn        *dipc;
  1261. Xunsigned long    offset;
  1262. X{
  1263. X    unsigned long    new_stack_region_size;
  1264. X    unsigned char    *new_stack_region;
  1265. X
  1266. X    wcache_clear();
  1267. X
  1268. X    if (offset < STACK_MIN)
  1269. X    {
  1270. X        GLOBALdipc = dipc;
  1271. X        vcouldnot("grow stack to address 0x%x: below 0x%x", offset, STACK_MIN);
  1272. X        return -1;
  1273. X    }
  1274. X
  1275. X    new_stack_region_size = STACK_MAX + 1 - offset;
  1276. X    new_stack_region_size += 4096;    /* slop */
  1277. X    new_stack_region_size &= ~0xF;    /* Quadword aligned */
  1278. X
  1279. X    if ((new_stack_region = calloc(new_stack_region_size / 16, sizeof(unsigned char) * 16)) == (unsigned char *)0)
  1280. X    {
  1281. X        GLOBALdipc = dipc;
  1282. X        vcouldnot("grow stack to %d bytes", new_stack_region_size);
  1283. X        return -1;
  1284. X    }
  1285. X
  1286. X    if (P.p_stack_region != (unsigned char *)0)
  1287. X    {
  1288. X        unsigned long    p_stack_region_size;
  1289. X
  1290. X        p_stack_region_size = STACK_MAX + 1 - P.p_stack_region_min;
  1291. X
  1292. X        (void)memcpy(&new_stack_region[new_stack_region_size - p_stack_region_size], P.p_stack_region, p_stack_region_size);
  1293. X        (void)free(P.p_stack_region);
  1294. X    }
  1295. X
  1296. X    P.p_stack_region = new_stack_region;
  1297. X    P.p_stack_region_min = STACK_MAX + 1 - new_stack_region_size;
  1298. X
  1299. X    return 0;
  1300. X}
  1301. X
  1302. Xint
  1303. Xquiet_procmget(dipc, offset, cp, length)
  1304. Xdinstrn        *dipc;
  1305. Xunsigned long    offset;
  1306. Xunsigned char    *cp;
  1307. Xint        length;
  1308. X{
  1309. X    unsigned long    limit;
  1310. X    int        i;
  1311. X
  1312. X    if (length == 0)
  1313. X        return 0;
  1314. X
  1315. X    limit = offset + length - 1;
  1316. X
  1317. X    if (limit <= P.p_text_region_limit)
  1318. X    {
  1319. X        if ((i = offset - P.p_text_region_min) < 0)
  1320. X        {
  1321. X            GLOBALdipc = dipc;
  1322. X            vcouldnot("read %d byte%s at text address 0x%x: illegal (too small) address", length, (length == 1) ? "" : "s", offset);
  1323. X            return -1;
  1324. X        }
  1325. X
  1326. X        Wmemcpy(cp, &P.p_text_region[i], length);
  1327. X    }
  1328. X    else if (limit <= P.p_data_region_limit)
  1329. X    {
  1330. X        if ((i = offset - P.p_data_region_min) < 0)
  1331. X        {
  1332. X            GLOBALdipc = dipc;
  1333. X            vcouldnot("read %d byte%s at data address 0x%x: illegal (too small) address", length, (length == 1) ? "" : "s", offset);
  1334. X            return -1;
  1335. X        }
  1336. X
  1337. X        Wmemcpy(cp, &P.p_data_region[i], length);
  1338. X    }
  1339. X    else if (limit <= STACK_MAX)
  1340. X    {
  1341. X        if ((i = offset - P.p_stack_region_min) < 0)
  1342. X        {
  1343. X            if (proc_grow_stack(dipc, offset) == -1)
  1344. X                return -1;
  1345. X
  1346. X            i = offset - P.p_stack_region_min;
  1347. X        }
  1348. X
  1349. X        Wmemcpy(cp, &P.p_stack_region[i], length);
  1350. X    }
  1351. X    else
  1352. X    {
  1353. X        /*
  1354. X         * Hole above Stack space.
  1355. X         */
  1356. X        GLOBALdipc = dipc;
  1357. X        vcouldnot("read %d byte%s at data address 0x%x: illegal (i.e. too big) address", length, (length == 1) ? "" : "s", offset);
  1358. X        return -1;
  1359. X    }
  1360. X
  1361. X    return 0;
  1362. X}
  1363. X
  1364. Xint
  1365. Xprocmget(dipc, offset, cp, length)
  1366. Xdinstrn        *dipc;
  1367. Xunsigned long    offset;
  1368. Xunsigned char    *cp;
  1369. Xint        length;
  1370. X{
  1371. X    int    result;
  1372. X
  1373. X    result = quiet_procmget(dipc, offset, cp, length);
  1374. X
  1375. X    if (Mflag)
  1376. X        procmget_trace(offset, cp, length);
  1377. X
  1378. X    return result;
  1379. X}
  1380. X
  1381. Xint
  1382. Xproc_mem_contiguous(offset, length, p)
  1383. Xunsigned long    offset;
  1384. Xint        length;
  1385. Xchar        **p;
  1386. X{
  1387. X    unsigned long    limit;
  1388. X
  1389. X    limit = offset + length - 1;
  1390. X
  1391. X    if
  1392. X    (
  1393. X        offset >= P.p_text_region_min
  1394. X        &&
  1395. X        limit <= P.p_text_region_limit
  1396. X    )
  1397. X    {
  1398. X        if (p != (char **)0)
  1399. X            *p = &P.p_text_region[offset - P.p_text_region_min];
  1400. X        return 1;
  1401. X    }
  1402. X
  1403. X    if
  1404. X    (
  1405. X        offset >= P.p_data_region_min
  1406. X        &&
  1407. X        limit <= P.p_data_region_limit
  1408. X    )
  1409. X    {
  1410. X        if (p != (char **)0)
  1411. X            *p = &P.p_data_region[offset - P.p_data_region_min];
  1412. X        return 1;
  1413. X    }
  1414. X
  1415. X    if
  1416. X    (
  1417. X        offset >= P.p_stack_region_min
  1418. X        &&
  1419. X        limit <= STACK_MAX
  1420. X    )
  1421. X    {
  1422. X        if (p != (char **)0)
  1423. X            *p = &P.p_stack_region[offset - P.p_stack_region_min];
  1424. X        return 1;
  1425. X    }
  1426. X
  1427. X    return 0;
  1428. X}
  1429. X
  1430. Xint
  1431. Xquiet_procmput(dipc, offset, cp, length)
  1432. Xdinstrn        *dipc;
  1433. Xunsigned long    offset;
  1434. Xunsigned char    *cp;
  1435. Xint        length;
  1436. X{
  1437. X    unsigned long    limit;
  1438. X    int        i;
  1439. X
  1440. X    if (length == 0)
  1441. X        return 0;
  1442. X
  1443. X    limit = offset + length - 1;
  1444. X
  1445. X    if (offset < P.p_text_region_min)
  1446. X    {
  1447. X        /*
  1448. X         * Hole before text.
  1449. X         */
  1450. X        GLOBALdipc = dipc;
  1451. X        vcouldnot("write %d byte%s at address 0x%x: illegal (i.e. too small) address", length, (length == 1) ? "" : "s", offset);
  1452. X        return -1;
  1453. X    }
  1454. X
  1455. X    if (offset <= P.p_text_region_limit)
  1456. X    {
  1457. X        int    tlength;
  1458. X
  1459. X        /*
  1460. X         * Text (or Readonly Data?) space.
  1461. X         */
  1462. X        if (P.p_text_region_is_readonly)
  1463. X        {
  1464. X            GLOBALdipc = dipc;
  1465. X            vcouldnot("write %d byte%s at address 0x%x: readonly (text or data) address", length, (length == 1) ? "" : "s", offset);
  1466. X            return -1;
  1467. X        }
  1468. X
  1469. X        if (limit > P.p_text_region_limit)
  1470. X            tlength = P.p_text_region_limit + 1 - offset;
  1471. X        else
  1472. X            tlength = length;
  1473. X
  1474. X        Wmemcpy(&P.p_text_region[offset - P.p_text_region_min], cp, tlength);
  1475. X
  1476. X        /*
  1477. X         * Disable decoded instructions for this range.
  1478. X         */
  1479. X        {
  1480. X            int        t;
  1481. X            unsigned long    o;
  1482. X
  1483. X            t = tlength;
  1484. X            o = offset;
  1485. X
  1486. X            while (t > 0)
  1487. X            {
  1488. X                int    remainder;
  1489. X
  1490. X                if (clear_decoded_page(dipc, o, &remainder) == -1)
  1491. X                    return -1;
  1492. X
  1493. X                o += remainder;
  1494. X                t -= remainder;
  1495. X            }
  1496. X        }
  1497. X
  1498. X        offset += tlength;
  1499. X        cp += tlength;
  1500. X        length -= tlength;
  1501. X
  1502. X        if (length == 0)
  1503. X            return 0;
  1504. X    }
  1505. X
  1506. X    if ((i = offset - P.p_data_region_min) < 0)
  1507. X    {
  1508. X        /*
  1509. X         * Hole between text and data.
  1510. X         */
  1511. X        GLOBALdipc = dipc;
  1512. X        vcouldnot("write %d byte%s at address 0x%x: illegal (i.e. unmapped) address between text and data regions", length, (length == 1) ? "" : "s", offset);
  1513. X        return -1;
  1514. X    }
  1515. X
  1516. X    if (limit <= P.p_data_region_limit)
  1517. X    {
  1518. X        /*
  1519. X         * Data space.
  1520. X         */
  1521. X        Wmemcpy(&P.p_data_region[i], cp, length);
  1522. X        return 0;
  1523. X    }
  1524. X
  1525. X    if (limit <= STACK_MAX)
  1526. X    {
  1527. X        /*
  1528. X         * Stack space.
  1529. X         */
  1530. X        if ((i = offset - P.p_stack_region_min) < 0)
  1531. X        {
  1532. X            if (proc_grow_stack(dipc, offset) == -1)
  1533. X                return -1;
  1534. X
  1535. X            i = offset - P.p_stack_region_min;
  1536. X        }
  1537. X
  1538. X        Wmemcpy(&P.p_stack_region[i], cp, length);
  1539. X        return 0;
  1540. X    }
  1541. X
  1542. X    /*
  1543. X     * Hole above Stack space.
  1544. X     */
  1545. X    GLOBALdipc = dipc;
  1546. X    vcouldnot("write %d byte%s starting at address 0x%x: illegal (i.e. too big) address", length, (length == 1) ? "" : "s", offset);
  1547. X    return -1;
  1548. X}
  1549. X
  1550. Xint
  1551. Xprocmput(dipc, offset, cp, length)
  1552. Xdinstrn        *dipc;
  1553. Xunsigned long    offset;
  1554. Xunsigned char    *cp;
  1555. Xint        length;
  1556. X{
  1557. X    if (Mflag)
  1558. X        procmput_trace(offset, cp, length);
  1559. X
  1560. X    return quiet_procmput(dipc, offset, cp, length);
  1561. X}
  1562. X
  1563. Xchar    *
  1564. Xproc_text_address(text_address)
  1565. Xunsigned long    text_address;
  1566. X{
  1567. X    return symtab_text_address((P.p_adotout == (char *)0) ? (symtab *)0 : &P.p_symtab, text_address);
  1568. X}
  1569. X
  1570. Xint
  1571. Xquiet_procsget(r, v)
  1572. Xint        r;
  1573. Xunsigned long    *v;
  1574. X{
  1575. X    int    saved_Rflag;
  1576. X
  1577. X    saved_Rflag = Rflag;
  1578. X    Rflag = 0;
  1579. X    procsget(r, *v);
  1580. X    Rflag = saved_Rflag;
  1581. X
  1582. X    return 0;
  1583. X}
  1584. X
  1585. Xint
  1586. Xquiet_procsput(r, v)
  1587. Xint        r;
  1588. Xunsigned long    v;
  1589. X{
  1590. X    int    saved_Rflag;
  1591. X
  1592. X    saved_Rflag = Rflag;
  1593. X    Rflag = 0;
  1594. X    procsput(r, v);
  1595. X    Rflag = saved_Rflag;
  1596. X
  1597. X    return 0;
  1598. X}
  1599. X
  1600. Xint
  1601. Xquiet_procbreakget(v)
  1602. Xunsigned long    *v;
  1603. X{
  1604. X    int    result;
  1605. X    int    saved_Rflag;
  1606. X
  1607. X    saved_Rflag = Rflag;
  1608. X    Rflag = 0;
  1609. X    result = procbreakget(v);
  1610. X    Rflag = saved_Rflag;
  1611. X
  1612. X    return result;
  1613. X}
  1614. X
  1615. Xint
  1616. Xquiet_procbreakput(v)
  1617. Xunsigned long    v;
  1618. X{
  1619. X    int    result;
  1620. X    int    saved_Rflag;
  1621. X
  1622. X    saved_Rflag = Rflag;
  1623. X    Rflag = 0;
  1624. X    result = procbreakput(v);
  1625. X    Rflag = saved_Rflag;
  1626. X
  1627. X    return result;
  1628. X}
  1629. X
  1630. Xint
  1631. Xquiet_procwrdataput(v)
  1632. Xunsigned long    v;
  1633. X{
  1634. X    int    result;
  1635. X    int    saved_Rflag;
  1636. X
  1637. X    saved_Rflag = Rflag;
  1638. X    Rflag = 0;
  1639. X    result = procwrdataput(v);
  1640. X    Rflag = saved_Rflag;
  1641. X
  1642. X    return result;
  1643. X}
  1644. X
  1645. Xint
  1646. Xmagic_ok(filename)
  1647. Xchar    *filename;
  1648. X{
  1649. X    int        fd;
  1650. X    int        saved_errno;
  1651. X    unsigned short    smagic;
  1652. X
  1653. X    saved_errno = errno;
  1654. X
  1655. X    if ((fd = open(filename, O_RDONLY)) == -1)
  1656. X        return 0;
  1657. X
  1658. X    if (read(fd, (unsigned char *)&smagic, sizeof(smagic)) != sizeof(smagic))
  1659. X    {
  1660. X        saved_errno = errno;
  1661. X        (void)close(fd);
  1662. X        errno = saved_errno;
  1663. X        return 0;
  1664. X    }
  1665. X
  1666. X    (void)close(fd);
  1667. X
  1668. X    if
  1669. X    (
  1670. X        smagic == MIPSEBMAGIC
  1671. X        ||
  1672. X        smagic == MIPSELMAGIC
  1673. X        ||
  1674. X        smagic == SMIPSEBMAGIC
  1675. X        ||
  1676. X        smagic == SMIPSELMAGIC
  1677. X        ||
  1678. X        smagic == MIPSEBUMAGIC
  1679. X        ||
  1680. X        smagic == MIPSELUMAGIC
  1681. X        ||
  1682. X        smagic == MIPSEBMAGIC_2
  1683. X        ||
  1684. X        smagic == MIPSELMAGIC_2
  1685. X        ||
  1686. X        smagic == SMIPSEBMAGIC_2
  1687. X        ||
  1688. X        smagic == SMIPSELMAGIC_2
  1689. X        ||
  1690. X        smagic == MIPSEBMAGIC_3
  1691. X        ||
  1692. X        smagic == MIPSELMAGIC_3
  1693. X        ||
  1694. X        smagic == SMIPSEBMAGIC_3
  1695. X        ||
  1696. X        smagic == SMIPSELMAGIC_3
  1697. X    )
  1698. X    {
  1699. X        errno = saved_errno;
  1700. X        return 1;
  1701. X    }
  1702. X
  1703. X    if
  1704. X    (
  1705. X        ((unsigned char *)&smagic)[0] == '#'
  1706. X        &&
  1707. X        ((unsigned char *)&smagic)[1] == '!'
  1708. X    )
  1709. X    {
  1710. X        errno = saved_errno;
  1711. X        return 2;
  1712. X    }
  1713. X
  1714. X    errno = ENOEXEC;
  1715. X
  1716. X    return 0;
  1717. X}
  1718. X
  1719. Xint
  1720. Xinterpreter_ok(filename)
  1721. Xchar    *filename;
  1722. X{
  1723. X    int    fd;
  1724. X    int    saved_errno;
  1725. X    char    interpreter_data[64 + 1];
  1726. X    char    *new_filename;
  1727. X    char    *cp;
  1728. X
  1729. X    saved_errno = errno;
  1730. X
  1731. X    if ((fd = open(filename, O_RDONLY)) == -1)
  1732. X        return 0;
  1733. X
  1734. X    /*
  1735. X     * Skip the magic number -- we know
  1736. X     * it looks ok.
  1737. X     */
  1738. X    if (lseek(fd, 2, 0) == -1)
  1739. X    {
  1740. X        saved_errno = errno;
  1741. X        (void)close(fd);
  1742. X        errno = saved_errno;
  1743. X        return 0;
  1744. X    }
  1745. X
  1746. X    bzero(&interpreter_data[0], sizeof(interpreter_data));
  1747. X
  1748. X    if (read(fd, &interpreter_data[0], sizeof(interpreter_data) - 1) <= 0)
  1749. X    {
  1750. X        saved_errno = errno;
  1751. X        (void)close(fd);
  1752. X        errno = saved_errno;
  1753. X        return 0;
  1754. X    }
  1755. X
  1756. X    (void)close(fd);
  1757. X
  1758. X    /*
  1759. X     * Skip leading white space.
  1760. X     */
  1761. X    for (new_filename = &interpreter_data[0]; *new_filename == ' ' || *new_filename == '\t'; new_filename++)
  1762. X        ;
  1763. X
  1764. X    /*
  1765. X     * Terminate the filename with a '\0'.
  1766. X     */
  1767. X    for (cp = new_filename; *cp != ' ' && *cp != '\t' && *cp != '\n' && *cp != '\0'; cp++)
  1768. X        ;
  1769. X
  1770. X    *cp = '\0';
  1771. X
  1772. X    if (magic_ok(new_filename) == 1)
  1773. X    {
  1774. X        errno = saved_errno;
  1775. X        return 1;
  1776. X    }
  1777. X
  1778. X    errno = ENOEXEC;
  1779. X
  1780. X    return 0;
  1781. X}
  1782. X
  1783. Xint
  1784. Xget_interpreter_data(filename, interpreter_namep, interpreter_argp)
  1785. Xchar    *filename;
  1786. Xchar    **interpreter_namep;
  1787. Xchar    **interpreter_argp;
  1788. X{
  1789. X    int        saved_errno;
  1790. X    int        fd;
  1791. X    static char    interpreter_data[64 + 1];
  1792. X    char        *new_filename;
  1793. X    char        *cp;
  1794. X    int        savedc;
  1795. X
  1796. X    saved_errno = errno;
  1797. X
  1798. X    if ((fd = open(filename, O_RDONLY)) == -1)
  1799. X    {
  1800. X        (void)close(fd);
  1801. X        errno = saved_errno;
  1802. X        return -1;
  1803. X    }
  1804. X
  1805. X    bzero(&interpreter_data[0], sizeof(interpreter_data));
  1806. X
  1807. X    if (read(fd, &interpreter_data[0], sizeof(interpreter_data) - 1) < 3)
  1808. X    {
  1809. X        (void)close(fd);
  1810. X        errno = saved_errno;
  1811. X        return -1;
  1812. X    }
  1813. X
  1814. X    (void)close(fd);
  1815. X
  1816. X    errno = saved_errno;
  1817. X
  1818. X    if
  1819. X    (
  1820. X        interpreter_data[0] != '#'
  1821. X        ||
  1822. X        interpreter_data[1] != '!'
  1823. X    )
  1824. X        return -1;
  1825. X
  1826. X    /*
  1827. X     * Skip leading white space.
  1828. X     */
  1829. X    for (new_filename = &interpreter_data[2]; *new_filename == ' ' || *new_filename == '\t'; new_filename++)
  1830. X        ;
  1831. X
  1832. X    *interpreter_namep = new_filename;
  1833. X
  1834. X    /*
  1835. X     * Terminate the filename with a '\0'.
  1836. X     */
  1837. X    for (cp = new_filename; *cp != ' ' && *cp != '\t' && *cp != '\n' && *cp != '\0'; cp++)
  1838. X        ;
  1839. X
  1840. X    savedc = *cp;
  1841. X    *cp++ = '\0';
  1842. X
  1843. X    if (savedc == '\n' || savedc == '\0')
  1844. X        return 0;
  1845. X
  1846. X    /*
  1847. X     * Skip any further white space.
  1848. X     */
  1849. X    while (*cp == ' ' || *cp == '\t')
  1850. X        cp++;
  1851. X
  1852. X    if (*cp == '\n' || *cp == '\0')
  1853. X        return 0;
  1854. X
  1855. X    *interpreter_argp = cp;
  1856. X
  1857. X    /*
  1858. X     * Terminate the argument with a '\0'.
  1859. X     */
  1860. X    while (*cp != '\n' && *cp != '\0')
  1861. X        cp++;
  1862. X
  1863. X    *cp = '\0';
  1864. X
  1865. X    return 0;
  1866. X}
  1867. X
  1868. Xint
  1869. Xis_a_shared_library(filename)
  1870. Xchar    *filename;
  1871. X{
  1872. X    /*
  1873. X     * TODO: check for shared libraries.
  1874. X     */
  1875. X    return 0;
  1876. X}
  1877. END_OF_FILE
  1878. if test 25029 -ne `wc -c <'process.c'`; then
  1879.     echo shar: \"'process.c'\" unpacked with wrong size!
  1880. fi
  1881. # end of 'process.c'
  1882. fi
  1883. echo shar: End of archive 4 \(of 8\).
  1884. cp /dev/null ark4isdone
  1885. MISSING=""
  1886. for I in 1 2 3 4 5 6 7 8 ; do
  1887.     if test ! -f ark${I}isdone ; then
  1888.     MISSING="${MISSING} ${I}"
  1889.     fi
  1890. done
  1891. if test "${MISSING}" = "" ; then
  1892.     echo You have unpacked all 8 archives.
  1893.     rm -f ark[1-9]isdone
  1894. else
  1895.     echo You still need to unpack the following archives:
  1896.     echo "        " ${MISSING}
  1897. fi
  1898. ##  End of shell archive.
  1899. exit 0
  1900.